<template>
  <div>
    <div class="inspection_evaluation">
      <div class="panel_header">
        <i class="iconfont">&#xe66d;</i>
        供应商考察评估结果
      </div>
      <div class="inspection_evaluation_list">
        <el-form :model="formCode">
          <el-row>
            <el-col :span="4" class="col_label">供应商编码</el-col>
            <el-col :span="4" class="col_view">{{formCode.vendorCode}}</el-col>
            <el-col :span="4" class="col_label">ERP代码</el-col>
            <el-col :span="4" class="col_view">{{formCode.vendorErpCode}}</el-col>
            <el-col :span="4" class="col_label">供应商名称</el-col>
            <el-col :span="4" class="col_view">{{formCode.vendorName}}</el-col>
          </el-row>
        </el-form>
      </div>
      <h3 class="panel-title">
        <i class="iconfont">&#xe66d;</i>
        评分结果
      </h3>
      <div class="inspection_evaluation_list">
        <el-form :model="form" label-width="177px">
          <el-row>
            <el-col :span="4" class="col_label">是否需要整改</el-col>
            <el-col :span="20" class="col_view">{{form.improveFlag== 1 ? '是' : '否'}}</el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="col_label">复评方式</el-col>
            <el-col :span="20" class="col_view">{{form.reviewWay== 1 ? '现场复审' : '整改报告'}}</el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="col_label">
              <div class="improveRequirement improveRequirement_left">整改意见</div>
            </el-col>
            <el-col :span="20" class="col_view">
              <div class="improveRequirement">{{form.improveRequirement}}</div>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <h3 class="panel-title">
        整改
      </h3>
      <div class="inspection_evaluation_list">
        <el-form :model="formInline" :rules="rules" ref="formInline" label-width="100px">
          <el-form-item label="附件上传：">
            <el-upload class="upload-file" ref="upload" :action="this.lib.config.host.system + '/common/fileupload/upload'" :data=fileData
              :limit="1" :on-success="uploadSuccess" :file-list="fileList">
              <el-button slot="trigger" type="primary">选取文件</el-button>
            </el-upload>
          </el-form-item>
          <el-form-item label="整改反馈" prop="feedback">
            <el-input type="textarea" maxlength='200' :autosize="{ minRows: 2, maxRows: 6}" v-model="formInline.feedback"></el-input>
          </el-form-item>
          <div class="clearfix">
            <router-link to="/Index/VendorDlv/vendorInspectionEvaluation">
              <el-button class="fr fr_right">返回</el-button>
            </router-link>
            <el-button class="fr fr_right" type="primary" @click="submitForm('formInline','/vendormgt/dlv/factoryInspect/score/feedback')">提交</el-button>
          </div>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        rules: {
          feedback: [{
            required: true,
            message: '请填写整改反馈',
            trigger: 'blur'
          }]
        },
        fileList: [],
        // 定义附件的业务模块和业务动作
        fileData: {
          busAction: "VD_FEEDBACK_RESULT",
          tableName: "VD_DLV_ASSESS_RESULT",
          tableId: this.$route.query.id
        },
        formInline: {
          feedback: '',
          attId: '',
          id: this.$route.query.id
        },
        form: {
          checkStatus: ''
        },
        formCode: {}
      }
    },
    created() {
      this.init();
    },
    methods: {
      // 自动上传附件后返回附件url和name
      uploadSuccess: function (response) {
        //附件上传成功回调
        this.formInline.attId = response.id;
      },
      init() {
        //获取供应商评分结果
        this.axios.post(this.lib.config.host.vendorDlv + '/vendormgt/dlv/factoryInspect/score/toViewScoreItem/' + this.$route
            .query.id)
          .then((response) => {
            this.form = response.data;
            this.formCode = response.data.inspectItem;
          })
          .catch(function (error) {
            console.log(error);
          });
      },
      //提交整改反馈
      submitForm(formName, url) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$confirm('是否执行此操作?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.axios.post(this.lib.config.host.vendorDlv + url, this.formInline)
                .then((response) => {
                  this.$message({
                    type: 'success',
                    message: '操作成功!'
                  });
                  this.$router.push('/Index/VendorDlv/VendorInspectionEvaluation');
                })
                .catch((error) => {
                  console.log(error);
                })
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消此操作'
              });
            });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
    }
  }

</script>
<style scoped>
  .form_label {
    height: 96px;
    line-height: 96px;
    font-size: 12px;
    color: #000000;
    border: 1px solid #d4d4d4;
    border-top: none;
  }

  .form_textarea {
    border-radius: 0;
    font-size: 12px;
    color: #000000;
    border-top: none;
  }

</style>
